package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.dao.SetMealDao;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Order;
import com.itheima.health.service.OrderService;
import com.itheima.health.service.SmsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

@RestController
@RequestMapping("/mobile/order")
@Slf4j
public class MobileOrderController {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private OrderService orderService;
    @Autowired
    private SmsService smsService;
    @PostMapping("/submit")
    public Result add(@RequestBody Map<String,String> map){

        if (!smsService.checkValidateCode("ORDER", map.get("telephone"),map.get("validateCode"))) {
            return new Result(false, MessageConst.VALIDATECODE_ERROR);
        }

        log.info("[检查项-新增]data:{}",map);
        orderService.add(map);
        return new Result(true, MessageConst.ADD_CHECKITEM_SUCCESS);
    }
    @GetMapping("/findById")
    public Result findById(Integer id){
        Map<String,Object> byId = orderService.findById(id);
        byId.put("orderDate",new SimpleDateFormat("yyyy-MM-dd").format(byId.get("orderDate")));
        return new Result(true,MessageConst.QUERY_ORDER_SUCCESS,byId);

    }
}
